'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 用户相关
 * @author sundbcn@gmail.com (sun debing)
 */

var async = require('async');
var Code = require('../../../consts/code');
var PlayerManager = require('../../../libs/playerManager');
var marqueeModel = require('../../../models/marqueeModel.js');
var moment = require('moment');

module.exports = function (app) {
    return new Handler(app);
};

var Handler = function (app) {
    this.app = app;
};

/**
 * 跑马灯公告(后台)
 */
Handler.prototype.sendMsg = function (msg, session, next) {
    var sort_id = msg.query.sort_id || 1;
    var text = msg.query.text || '';
    var is_time = msg.query.is_time || 0;
    var times = msg.query.times || 1;
    var create_time = msg.query.create_time || moment().unix();
    var interval_time = msg.query.interval_time || 1;

    async.waterfall(
        [
            function (cb) {
                var msg_list = {
                    sort_id: sort_id, //优先级
                    text: text, // 发送文本
                    is_time: is_time, // 是否定时任务   0不是定时任务     1定时任务
                    times: times, // 发送次数
                    create_time: create_time, // 发送信息时间
                    interval_time: interval_time // 间隔时间
                };
                marqueeModel.create(msg_list, function (err, module) {});
                cb();
            }
        ],
        function (err) {
            if (!!err) {
                console.error(err);
                return next(null, {
                    code: Code.FAIL
                });
            }
            return next(null, {
                code: Code.OK
            });
        }
    );
};
